package JUC.回调_竟然是个设计模式;

public class Local implements CallBack,Runnable{
    /*变量准备*/
    public Remote remote;
    public String message;
    public Local(Remote remote,String message){
        this.remote = remote;
        this.message = message;
    }
    @Override
    public void execute(Object... objects) {
        System.out.println("回来了嘻嘻 我不叫main,而是叫"+Thread.currentThread().getName());
    }


    /*嵌套调用*/
    public static void main(String[] args) {
        Local local = new Local(new Remote(), "hello World");
        local.sendMessage();
        System.out.println("main2, 由于不是多线程，而是同步f()f(), 所以是启动完异步执行到此");
    }
    public void sendMessage(){
        System.out.println(Thread.currentThread().getName()+"main1");
        Thread thread = new Thread(this);
        thread.start();
        System.out.println("启动异步第2线程");
    }
    @Override
    public void run() {
        //回调说白了就是：把自己这个类 作为参数this 传过去 另个函数执行完回来调父方法 【一般应用结合多线程，合理分配 run / execute】
        remote.executeMessage(message, this);
    }
}